package com.one.group.admin.controller;

import com.one.group.model.entity.DecorationCharge;
import com.one.group.result.Result;
import com.one.group.service.DecorationChargeService;
import com.one.group.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 装修收费控制器
 */
@RestController
@RequestMapping("/decoration-charge")
public class DecorationChargeController {

    @Autowired
    private DecorationChargeService decorationChargeService;

    /**
     * 新增装修收费记录
     * @param decorationCharge 装修收费记录
     * @return 操作结果
     */
    @PostMapping("/add")
    public Result<?> addDecorationCharge(@RequestBody DecorationCharge decorationCharge) {
        try {
            boolean success = decorationChargeService.saveDecorationCharge(decorationCharge);
            if (success) {
                return ResultUtil.success("新增成功");
            } else {
                return ResultUtil.error(500,"新增失败");
            }
        } catch (Exception e) {
            return ResultUtil.error(500,"系统异常: " + e.getMessage());
        }
    }
    
    /**
     * 根据装修ID查询收费记录
     * @param decorationId 装修ID
     * @return 收费记录列表
     */
    @GetMapping("/list-by-decoration/{decorationId}")
    public Result<?> getByDecorationId(@PathVariable Long decorationId) {
        try {
            return ResultUtil.success(decorationChargeService.findByDecorationId(decorationId));
        } catch (Exception e) {
            return ResultUtil.error(500,"系统异常: " + e.getMessage());
        }
    }
}